﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Roslyn.Compilers.Common;
using Roslyn.Services;

namespace Analysis.Rules
{
    class ObjectInvocationIsDisposableVolatileChecker : IVolatileChecker
    {
        private IRoslynHelper helper;

        public ObjectInvocationIsDisposableVolatileChecker(IRoslynHelper helper)
        {
            this.helper = helper;
        }
        // We have a dependency on a concrete static class that returns something that interacts with the environment
        // Is Ok when:
        // 1. we return 
        public bool IsVolatile(Roslyn.Compilers.Common.CommonSyntaxNode node, Roslyn.Services.IDocument doc)
        {
            var t = helper.GetTypeAndSymbol(node, doc);
            if (t.Item2 == null)
                return true;
            return t.Item2.IsStatic && t.Item1.AllInterfaces.Any(i => i.Name.Contains("IDisposable"));
        }
    }
}
